home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectMusic / DMDrums / main.frm (.txt) next >
Encoding:
Visual Basic Form  |  2001-10-08  |  18.6 KB  |  592 lines

  1. VERSION 5.00
  2. Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
  3. Begin VB.Form main 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "DMDrums"
  6.    ClientHeight    =   5505
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   6255
  10.    Icon            =   "main.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   5505
  14.    ScaleWidth      =   6255
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CheckBox chkReverb 
  17.       Caption         =   "Play with environmental reverb"
  18.       Height          =   255
  19.       Left            =   1140
  20.       TabIndex        =   39
  21.       Top             =   1500
  22.       Value           =   1  'Checked
  23.       Width           =   3015
  24.    End
  25.    Begin VB.CommandButton cmdExit 
  26.       Cancel          =   -1  'True
  27.       Caption         =   "Exit"
  28.       Height          =   495
  29.       Left            =   5340
  30.       TabIndex        =   31
  31.       Top             =   4980
  32.       Width           =   855
  33.    End
  34.    Begin MSComCtl2.UpDown UpDown_Volume 
  35.       Height          =   375
  36.       Left            =   1740
  37.       TabIndex        =   36
  38.       TabStop         =   0   'False
  39.       Top             =   960
  40.       Width           =   240
  41.       _ExtentX        =   423
  42.       _ExtentY        =   661
  43.       _Version        =   393216
  44.       Value           =   100
  45.       Max             =   100
  46.       Enabled         =   -1  'True
  47.    End
  48.    Begin MSComCtl2.UpDown UpDown_Tempo 
  49.       Height          =   375
  50.       Left            =   1740
  51.       TabIndex        =   35
  52.       TabStop         =   0   'False
  53.       Top             =   360
  54.       Width           =   240
  55.       _ExtentX        =   423
  56.       _ExtentY        =   661
  57.       _Version        =   393216
  58.       Value           =   120
  59.       Max             =   1000
  60.       Min             =   1
  61.       Enabled         =   -1  'True
  62.    End
  63.    Begin VB.TextBox EDIT_Tempo 
  64.       Height          =   375
  65.       Left            =   1200
  66.       MaxLength       =   4
  67.       TabIndex        =   0
  68.       Text            =   "120"
  69.       Top             =   360
  70.       Width           =   495
  71.    End
  72.    Begin VB.TextBox EDIT_Volume 
  73.       Height          =   375
  74.       Left            =   1200
  75.       TabIndex        =   1
  76.       Text            =   "100"
  77.       Top             =   960
  78.       Width           =   495
  79.    End
  80.    Begin VB.CommandButton Stop 
  81.       Height          =   495
  82.       Left            =   3720
  83.       Picture         =   "main.frx":0442
  84.       Style           =   1  'Graphical
  85.       TabIndex        =   3
  86.       Top             =   840
  87.       Width           =   495
  88.    End
  89.    Begin VB.CommandButton Play 
  90.       Height          =   495
  91.       Left            =   3120
  92.       Picture         =   "main.frx":08F8
  93.       Style           =   1  'Graphical
  94.       TabIndex        =   2
  95.       Top             =   840
  96.       Width           =   495
  97.    End
  98.    Begin VB.PictureBox Picture1 
  99.       BorderStyle     =   0  'None
  100.       Height          =   1695
  101.       Left            =   120
  102.       Picture         =   "main.frx":0E8A
  103.       ScaleHeight     =   1695
  104.       ScaleWidth      =   855
  105.       TabIndex        =   32
  106.       TabStop         =   0   'False
  107.       Top             =   120
  108.       Width           =   855
  109.    End
  110.    Begin VB.ListBox LIST_Grooves 
  111.       Height          =   2400
  112.       Left            =   4320
  113.       TabIndex        =   29
  114.       Top             =   840
  115.       Width           =   1815
  116.    End
  117.    Begin VB.ListBox LIST_Bands 
  118.       Height          =   1425
  119.       Left            =   4320
  120.       TabIndex        =   30
  121.       Top             =   3480
  122.       Width           =   1815
  123.    End
  124.    Begin VB.CommandButton Drum 
  125.       Caption         =   "High Q"
  126.       Height          =   495
  127.       Index           =   24
  128.       Left            =   3480
  129.       TabIndex        =   28
  130.       Top             =   4440
  131.       Width           =   735
  132.    End
  133.    Begin VB.CommandButton Drum 
  134.       Caption         =   "Scratch"
  135.       Height          =   495
  136.       Index           =   23
  137.       Left            =   2640
  138.       TabIndex        =   27
  139.       Top             =   4440
  140.       Width           =   735
  141.    End
  142.    Begin VB.CommandButton Drum 
  143.       Caption         =   "Sticks"
  144.       Height          =   495
  145.       Index           =   22
  146.       Left            =   1800
  147.       TabIndex        =   26
  148.       Top             =   4440
  149.       Width           =   735
  150.    End
  151.    Begin VB.CommandButton Drum 
  152.       Caption         =   "Hand Clap"
  153.       Height          =   495
  154.       Index           =   21
  155.       Left            =   960
  156.       TabIndex        =   25
  157.       Top             =   4440
  158.       Width           =   735
  159.    End
  160.    Begin VB.CommandButton Drum 
  161.       Caption         =   "Tamb- ourine"
  162.       Height          =   495
  163.       Index           =   20
  164.       Left            =   120
  165.       TabIndex        =   24
  166.       Top             =   4440
  167.       Width           =   735
  168.    End
  169.    Begin VB.CommandButton Drum 
  170.       Caption         =   "Jingle Bells"
  171.       Height          =   495
  172.       Index           =   19
  173.       Left            =   3480
  174.       TabIndex        =   23
  175.       Top             =   3840
  176.       Width           =   735
  177.    End
  178.    Begin VB.CommandButton Drum 
  179.       Caption         =   "Cast- anets"
  180.       Height          =   495
  181.       Index           =   18
  182.       Left            =   2640
  183.       TabIndex        =   22
  184.       Top             =   3840
  185.       Width           =   735
  186.    End
  187.    Begin VB.CommandButton Drum 
  188.       Caption         =   "Shaker"
  189.       Height          =   495
  190.       Index           =   17
  191.       Left            =   1800
  192.       TabIndex        =   21
  193.       Top             =   3840
  194.       Width           =   735
  195.    End
  196.    Begin VB.CommandButton Drum 
  197.       Caption         =   "Triangle"
  198.       Height          =   495
  199.       Index           =   16
  200.       Left            =   960
  201.       TabIndex        =   20
  202.       Top             =   3840
  203.       Width           =   735
  204.    End
  205.    Begin VB.CommandButton Drum 
  206.       Caption         =   "Cuica"
  207.       Height          =   495
  208.       Index           =   15
  209.       Left            =   120
  210.       TabIndex        =   19
  211.       Top             =   3840
  212.       Width           =   735
  213.    End
  214.    Begin VB.CommandButton Drum 
  215.       Caption         =   "High Block"
  216.       Height          =   495
  217.       Index           =   14
  218.       Left            =   3480
  219.       TabIndex        =   18
  220.       Top             =   3240
  221.       Width           =   735
  222.    End
  223.    Begin VB.CommandButton Drum 
  224.       Caption         =   "Low Block"
  225.       Height          =   495
  226.       Index           =   13
  227.       Left            =   2640
  228.       TabIndex        =   17
  229.       Top             =   3240
  230.       Width           =   735
  231.    End
  232.    Begin VB.CommandButton Drum 
  233.       Caption         =   "Guiro"
  234.       Height          =   495
  235.       Index           =   12
  236.       Left            =   1800
  237.       TabIndex        =   16
  238.       Top             =   3240
  239.       Width           =   735
  240.    End
  241.    Begin VB.CommandButton Drum 
  242.       Caption         =   "Agogo"
  243.       Height          =   495
  244.       Index           =   11
  245.       Left            =   960
  246.       TabIndex        =   15
  247.       Top             =   3240
  248.       Width           =   735
  249.    End
  250.    Begin VB.CommandButton Drum 
  251.       Caption         =   "Timbale"
  252.       Height          =   495
  253.       Index           =   10
  254.       Left            =   120
  255.       TabIndex        =   14
  256.       Top             =   3240
  257.       Width           =   735
  258.    End
  259.    Begin VB.CommandButton Drum 
  260.       Caption         =   "High Conga"
  261.       Height          =   495
  262.       Index           =   9
  263.       Left            =   3480
  264.       TabIndex        =   13
  265.       Top             =   2640
  266.       Width           =   735
  267.    End
  268.    Begin VB.CommandButton Drum 
  269.       Caption         =   "Low Conga"
  270.       Height          =   495
  271.       Index           =   8
  272.       Left            =   2640
  273.       TabIndex        =   12
  274.       Top             =   2640
  275.       Width           =   735
  276.    End
  277.    Begin VB.CommandButton Drum 
  278.       Caption         =   "Crash"
  279.       Height          =   495
  280.       Index           =   7
  281.       Left            =   1800
  282.       TabIndex        =   11
  283.       Top             =   2640
  284.       Width           =   735
  285.    End
  286.    Begin VB.CommandButton Drum 
  287.       Caption         =   "Splash"
  288.       Height          =   495
  289.       Index           =   6
  290.       Left            =   960
  291.       TabIndex        =   10
  292.       Top             =   2640
  293.       Width           =   735
  294.    End
  295.    Begin VB.CommandButton Drum 
  296.       Caption         =   "Ride"
  297.       Height          =   495
  298.       Index           =   5
  299.       Left            =   120
  300.       TabIndex        =   9
  301.       Top             =   2640
  302.       Width           =   735
  303.    End
  304.    Begin VB.CommandButton Drum 
  305.       Caption         =   "High Tom"
  306.       Height          =   495
  307.       Index           =   4
  308.       Left            =   3480
  309.       TabIndex        =   8
  310.       Top             =   2040
  311.       Width           =   735
  312.    End
  313.    Begin VB.CommandButton Drum 
  314.       Caption         =   "Mid Tom"
  315.       Height          =   495
  316.       Index           =   3
  317.       Left            =   2640
  318.       TabIndex        =   7
  319.       Top             =   2040
  320.       Width           =   735
  321.    End
  322.    Begin VB.CommandButton Drum 
  323.       Caption         =   "Low Tom"
  324.       Height          =   495
  325.       Index           =   2
  326.       Left            =   1800
  327.       TabIndex        =   6
  328.       Top             =   2040
  329.       Width           =   735
  330.    End
  331.    Begin VB.CommandButton Drum 
  332.       Caption         =   "Snare"
  333.       Height          =   495
  334.       Index           =   1
  335.       Left            =   960
  336.       TabIndex        =   5
  337.       Top             =   2040
  338.       Width           =   735
  339.    End
  340.    Begin VB.CommandButton Drum 
  341.       Caption         =   "Kick"
  342.       Height          =   495
  343.       Index           =   0
  344.       Left            =   120
  345.       TabIndex        =   4
  346.       Top             =   2040
  347.       Width           =   735
  348.    End
  349.    Begin VB.Label lblInfo 
  350.       BackStyle       =   0  'Transparent
  351.       Caption         =   "Drum Sets"
  352.       Height          =   255
  353.       Index           =   1
  354.       Left            =   4320
  355.       TabIndex        =   38
  356.       Top             =   3240
  357.       Width           =   1755
  358.    End
  359.    Begin VB.Label lblInfo 
  360.       BackStyle       =   0  'Transparent
  361.       Caption         =   "Grooves"
  362.       Height          =   255
  363.       Index           =   0
  364.       Left            =   4320
  365.       TabIndex        =   37
  366.       Top             =   600
  367.       Width           =   1755
  368.    End
  369.    Begin VB.Label Label2 
  370.       Caption         =   "Tempo:"
  371.       Height          =   255
  372.       Left            =   1200
  373.       TabIndex        =   34
  374.       Top             =   120
  375.       Width           =   615
  376.    End
  377.    Begin VB.Label Label1 
  378.       Caption         =   "Volume:"
  379.       Height          =   255
  380.       Left            =   1200
  381.       TabIndex        =   33
  382.       Top             =   720
  383.       Width           =   615
  384.    End
  385. Attribute VB_Name = "main"
  386. Attribute VB_GlobalNameSpace = False
  387. Attribute VB_Creatable = False
  388. Attribute VB_PredeclaredId = True
  389. Attribute VB_Exposed = False
  390. Option Explicit
  391. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  392. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  393. '  File:       main.frm
  394. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  395. Dim dx As New DirectX8
  396. Dim perf As DirectMusicPerformance8
  397. Dim loader As DirectMusicLoader8
  398. Dim style As DirectMusicStyle8
  399. Dim band As DirectMusicBand8
  400. Dim composer As DirectMusicComposer8
  401. Dim seg As DirectMusicSegment8
  402. Dim segBand As DirectMusicSegment8
  403. Dim segMotif() As DirectMusicSegment8
  404. Dim mediapath As String
  405. Dim mtTime As Long
  406. Private Sub chkReverb_Click()
  407.     'Ok, they want to switch the default audio paths
  408.     Dim dmPath As DirectMusicAudioPath8
  409.     If chkReverb.Value = vbUnchecked Then
  410.         Set dmPath = perf.CreateStandardAudioPath(DMUS_APATH_DYNAMIC_STEREO, 128, True)
  411.     Else
  412.         Set dmPath = perf.CreateStandardAudioPath(DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, True)
  413.     End If
  414.     perf.SetDefaultAudioPath dmPath
  415.     ChangeBands
  416. End Sub
  417. Private Sub cmdExit_Click()
  418.     Stop_Click
  419.     Unload Me
  420. End Sub
  421. Private Sub Drum_Click(Index As Integer)
  422.     Call perf.PlaySegmentEx(segMotif(Index), DMUS_SEGF_SECONDARY, 0)
  423. End Sub
  424. Private Sub EDIT_Tempo_KeyPress(KeyAscii As Integer)
  425.     If KeyAscii = vbKeyReturn Then
  426.         If Val(EDIT_Tempo.Text) > 0 And Val(EDIT_Tempo.Text) < 1001 And IsNumeric(EDIT_Tempo.Text) Then
  427.             UpDown_Tempo.Value = EDIT_Tempo.Text
  428.             ChangeTempo (UpDown_Tempo.Value)
  429.         Else
  430.             EDIT_Tempo.Text = UpDown_Tempo.Value
  431.         End If
  432.     End If
  433.     If KeyAscii = vbKeyReturn Then KeyAscii = 0
  434. End Sub
  435. Private Sub EDIT_Tempo_LostFocus()
  436.     If Val(EDIT_Tempo.Text) > 0 And Val(EDIT_Tempo.Text) < 1001 And IsNumeric(EDIT_Tempo.Text) Then
  437.         UpDown_Tempo.Value = EDIT_Tempo.Text
  438.         ChangeTempo (UpDown_Tempo.Value)
  439.     Else
  440.         EDIT_Tempo.Text = UpDown_Tempo.Value
  441.     End If
  442. End Sub
  443. Private Sub EDIT_Volume_KeyPress(KeyAscii As Integer)
  444.     If KeyAscii = vbKeyReturn Then
  445.         If IsNumeric(EDIT_Volume.Text) And Val(EDIT_Volume.Text) >= 0 And Val(EDIT_Volume.Text) < 101 Then
  446.             UpDown_Volume.Value = EDIT_Volume.Text
  447.             ChangeVolume UpDown_Volume.Value
  448.         Else
  449.             EDIT_Volume.Text = UpDown_Volume.Value
  450.         End If
  451.     End If
  452.     If KeyAscii = vbKeyReturn Then KeyAscii = 0
  453. End Sub
  454. Private Sub EDIT_Volume_LostFocus()
  455.     If IsNumeric(EDIT_Volume.Text) And Val(EDIT_Volume.Text) >= 0 And Val(EDIT_Volume.Text) < 101 Then
  456.         UpDown_Volume.Value = EDIT_Volume.Text
  457.         ChangeVolume UpDown_Volume
  458.     Else
  459.         EDIT_Volume.Text = UpDown_Volume.Value
  460.     End If
  461. End Sub
  462. Private Sub Form_Load()
  463.     Dim dmA As DMUS_AUDIOPARAMS, lCount As Long
  464.     Dim MotifName As String
  465.     mediapath = FindMediaDir("Drums!.sgt")
  466.     Set perf = dx.DirectMusicPerformanceCreate()
  467.     Set loader = dx.DirectMusicLoaderCreate()
  468.     Set composer = dx.DirectMusicComposerCreate()
  469.     'Make sure we can init the audio as well
  470.     On Error GoTo FailedInit
  471.     ' Initialize performance object to use its own DirectSound object
  472.     perf.InitAudio Me.hWnd, DMUS_AUDIOF_ALL, dmA, , DMUS_APATH_SHARED_STEREOPLUSREVERB, 128
  473.     ' SetMasterAutoDownload indicates we the perofmance object
  474.     ' to attempt to auto download DLS collections when reference in
  475.     ' sgt and sty files
  476.     Call perf.SetMasterAutoDownload(True)
  477.     Set style = loader.LoadStyle(mediapath & "drums!.sty")
  478.     Set seg = loader.LoadSegment(mediapath & "drums!.sgt")
  479.     Get_Bands
  480.     LIST_Grooves.AddItem ("Alternative")
  481.     LIST_Grooves.AddItem ("Blues")
  482.     LIST_Grooves.AddItem ("Country")
  483.     LIST_Grooves.AddItem ("Dance - Pop")
  484.     LIST_Grooves.AddItem ("Hard Rock")
  485.     LIST_Grooves.AddItem ("Hip Hop")
  486.     LIST_Grooves.AddItem ("Jazz")
  487.     LIST_Grooves.AddItem ("Latin")
  488.     LIST_Grooves.AddItem ("R & B")
  489.     LIST_Grooves.AddItem ("Rap")
  490.     LIST_Grooves.AddItem ("Soft Rock")
  491.     LIST_Grooves.AddItem ("World")
  492.     ' Download the default band so that we can play the drum pads immediately
  493.     ChangeBands
  494.     ChangeVolume UpDown_Volume.Value
  495.     ReDim segMotif(style.GetMotifCount() - 1)
  496.     For lCount = 0 To style.GetMotifCount() - 1
  497.         MotifName = style.GetMotifName(lCount)
  498.         'We could set the drum name here (but we'll just leave them hard coded)
  499.         'Drum(lCount).Caption = MotifName
  500.         Set segMotif(lCount) = style.GetMotif(MotifName)
  501.     Next
  502.     LIST_Grooves.ListIndex = 0
  503.     LIST_Bands.ListIndex = 0
  504.     Exit Sub
  505. FailedInit:
  506.     MsgBox "Could not initialize DirectMusic." & vbCrLf & "This sample will exit.", vbOKOnly Or vbInformation, "Exiting..."
  507.     Unload Me
  508. End Sub
  509. Private Sub Form_Unload(Cancel As Integer)
  510.     Dim lCount As Long
  511.     On Error Resume Next
  512.     If Not (segBand Is Nothing) Then
  513.         perf.StopEx segBand, 0, 0
  514.         segBand.Unload perf.GetDefaultAudioPath
  515.     End If
  516.     If Not (seg Is Nothing) Then perf.StopEx seg, 0, 0
  517.     Set seg = Nothing
  518.     For lCount = LBound(segMotif) To UBound(segMotif)
  519.         If Not (segMotif(lCount) Is Nothing) Then perf.StopEx segMotif(lCount), 0, 0
  520.         Set segMotif(lCount) = Nothing
  521.     Next
  522.     Set segBand = Nothing
  523.     Set style = Nothing
  524.     Set composer = Nothing
  525.     Set loader = Nothing
  526.     If Not (band Is Nothing) Then
  527.         Call band.Unload(perf)
  528.     End If
  529.     Set band = Nothing
  530.     If Not (perf Is Nothing) Then perf.CloseDown
  531.     Set perf = Nothing
  532. End Sub
  533. Private Sub Get_Bands()
  534.     Dim BandCount As Integer
  535.     Dim counter As Integer
  536.     BandCount = style.GetBandCount()
  537.     For counter = 0 To (BandCount - 1)
  538.         LIST_Bands.AddItem (style.GetBandName(BandCount - counter - 1))
  539.     Next counter
  540. End Sub
  541. Private Sub LIST_Bands_Click()
  542.     ChangeBands
  543. End Sub
  544. Private Sub LIST_Grooves_Click()
  545.     perf.SetMasterGrooveLevel ((LIST_Grooves.ListIndex * 8) + 1)
  546. End Sub
  547. Private Sub Play_Click()
  548.     PlaySeg
  549.     ChangeBands
  550.     chkReverb.Enabled = False
  551. End Sub
  552. Private Sub Stop_Click()
  553.     perf.StopEx seg, 0, 0
  554.     chkReverb.Enabled = True
  555. End Sub
  556. Private Sub UPDOWN_Tempo_Change()
  557.     EDIT_Tempo.Text = UpDown_Tempo.Value
  558.     ChangeTempo (UpDown_Tempo.Value)
  559. End Sub
  560. Private Sub UPDOWN_Volume_Change()
  561.     EDIT_Volume.Text = UpDown_Volume.Value
  562.     Call ChangeVolume(UpDown_Volume.Value)
  563. End Sub
  564. Private Sub ChangeBands()
  565.     If Not (band Is Nothing) Then
  566.         Call band.Unload(perf)
  567.     End If
  568.     If LIST_Bands = vbNullString Then
  569.         Set band = style.GetBand("Standard")
  570.     Else
  571.         Set band = style.GetBand(LIST_Bands)
  572.     End If
  573.     Call band.Download(perf)
  574.     Set segBand = band.CreateSegment()
  575.     segBand.Download perf.GetDefaultAudioPath
  576.     Call perf.PlaySegmentEx(segBand, DMUS_SEGF_SECONDARY, 0)
  577. End Sub
  578. Private Sub PlaySeg()
  579.     Call perf.PlaySegmentEx(seg, 0, 0)
  580. End Sub
  581. Private Sub ChangeTempo(tempo As Integer)
  582.     perf.SendTempoPMSG 0, DMUS_PMSGF_REFTIME, tempo
  583. End Sub
  584. Sub ChangeVolume(ByVal n As Long)
  585.     If n = 0 Then
  586.         n = -10000
  587.     Else
  588.         n = (-50 * (100 - n))
  589.     End If
  590.     perf.SetMasterVolume n
  591. End Sub
  592.